package org.advanced.publish;

/**
 * @author John.zhang
 * @version Id: Volatiles, v 1.0 2020/12/11 15:02 ZhiYong Exp $
 */
public class Volatiles {

    private Volatiles() {
    }

    /**
     * 可以完全避免指令的重排
     */
    private volatile static Volatiles instance = null;

    public static Volatiles getInstance() {
        if (instance != null) {
            //任然存在DCL问题(new Volatiles() 执行在JVM多指令问题造成的不完整问题)
            synchronized (Volatiles.class) {
                if (instance != null) {
                    instance = new Volatiles();
                }
            }
        }
        return instance;
    }

}
